package com.datoucai.service.impl;

import com.alibaba.fastjson.JSON;
import com.datoucai.common.dto.UserInfoDto;
import com.datoucai.dao.TbCommentDao;
import com.datoucai.dto.BatchQueryCommentDto;
import com.datoucai.dto.CommentDetailInfoDto;
import com.datoucai.dto.CommentInfoDto;
import com.datoucai.dto.CommentResultInfoDto;
import com.datoucai.param.SimpleCommentInfoDto;
import com.datoucai.entity.CommentEntity;
import com.datoucai.entity.CommentParam;
import com.datoucai.entity.TbComment;
import com.datoucai.entity.TbCommentExample;
import com.datoucai.enums.TbLikeTypeEnum;
import com.datoucai.mapper.CommentMapper;
import com.datoucai.param.HasLikeDto;
import com.datoucai.param.HasLikesParam;
import com.datoucai.param.ReplyInfoDto;
import com.datoucai.rpc.MediaRpcService;
import com.datoucai.rpc.UserRpcService;
import com.datoucai.service.ICommentService;
import com.datoucai.utils.CommentExtendUtils;
import com.datoucai.utils.DFAService;
import com.datoucai.utils.DateUtils;
import com.datoucai.utils.RedisUtils;
import com.datoucai.utils.TokenUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;


/**
 * 评论服务实现
 * @date 2024/09/04
 */
@Service
@Slf4j
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentMapper commentMapper;


    @Autowired
    private TbCommentDao commentDao;

    @Autowired
    private DFAService dfaService;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private UserRpcService  userRpcService;

    @Autowired
    private MediaRpcService mediaRpcService;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;


    /**
     * 增加评论
     * @param dto
     * @return int
     */
    @Override
    public int addComment(CommentInfoDto dto) {
        try {
            log.info("增加评论-service层-addComment-入参:{}", JSON.toJSONString(dto));
            // 敏感词检测和替换
            String content = dfaService.checkSensitiveWords(dto.getContent());
            TbComment tbComment = new TbComment();

            // 查询父评论的用户名
            if(dto.getParentCommentId()!=null){
                TbComment parentComment = commentDao.selectByPrimaryKey(dto.getParentCommentId());
                if(parentComment!=null){
                    dto.setRepliedUsername(CommentExtendUtils.getUsernameOnExtend(parentComment.getExtend()));
                    dto.setRepliedUserId(parentComment.getUserId()+"");
                    dto.setRootCommentId(parentComment.getRootCommentId()!=null? parentComment.getRootCommentId() : parentComment.getId());
                }
            }

            BeanUtils.copyProperties(dto,tbComment);
            tbComment.setContent(content);
            tbComment.setExtend(CommentExtendUtils.buildExtend(dto));
            // 插入评论
            int count = commentDao.insertSelective(tbComment);
            dto.setId(tbComment.getId());
            if(dto.getRootCommentId()==null){
                TbComment tbCommentParam = new TbComment();
                tbCommentParam.setId(tbComment.getId());
                tbCommentParam.setRootCommentId(tbComment.getId());
                commentDao.updateByPrimaryKeySelective(tbCommentParam);
            }
            log.info("增加评论-service层-addComment-出参:{}", count);
            // 发生增加评论消息
            sendAddCommentMessage(count,dto);
            return count;
        }catch (Exception e){
            log.error("增加评论-service层-addComment-异常:", e);
            return -1;
        }
    }

    /**
     * 发送成功发表评论消息
     * @param count
     * @param dto
     */
    private void sendAddCommentMessage(int count, CommentInfoDto dto) {
        if(count<1){
            return;
        }
        try {
            Message<CommentInfoDto> message = MessageBuilder.withPayload(dto).build();
            log.info("发送-发表评论消息-入参:{}", JSON.toJSONString(message));
            SendResult sendResult = rocketMQTemplate.syncSend("ADD_COMMENT_TOPIC", message);
            log.info("发送-发表评论消息-状态:{}", JSON.toJSONString(sendResult));
        }catch (Exception e){
            log.error("发送-发表评论消息-异常:",e);
        }
    }
    /**
     * 发送成功删除评论消息
     * @param count
     * @param dto
     */
    private void sendDelCommentMessage(int count, CommentInfoDto dto) {
        if(count<1){
            return;
        }
        try {
            Message<CommentInfoDto> message = MessageBuilder.withPayload(dto).build();
            log.info("发送-删除评论消息-入参:{}", JSON.toJSONString(message));
            SendResult sendResult = rocketMQTemplate.syncSend("DEL_COMMENT_TOPIC", message);
            log.info("发送-删除评论消息-状态:{}", JSON.toJSONString(sendResult));
        }catch (Exception e){
            log.error("发送-删除评论消息-异常:",e);
        }
    }

    /**
     * 删除评论
     * @param dto
     * @return
     */
    @Override
    public int deleteComment(CommentInfoDto dto) {
        try {
            log.info("删除评论-service层-deleteComment-入参:{}", JSON.toJSONString(dto));
            CommentParam updateParam = new CommentParam();
            updateParam.setId(dto.getId());
            updateParam.setModule(dto.getModule());
            updateParam.setUserId(dto.getUserId());
            updateParam.setIsDelete(dto.getIsDelete());
            updateParam.setUpdateTime(new Date());

            int count = commentMapper.updateCommentByParam(updateParam);
            log.info("删除评论-service层-deleteComment-出参:{}", count);
            // 发送删除评论的消息
            sendDelCommentMessage(count,dto);
            return count;
        }catch (Exception e){
            log.error("删除评论-service层-deleteComment-异常:", e);
            return -1;
        }

    }

    /**
     * 查询评论
     * @param dto
     * @return
     */
    @Override
    public CommentResultInfoDto queryCommentByParam(CommentInfoDto dto) {
        try {
            log.info("查询评论-service层-queryCommentByParam-入参:{}", JSON.toJSONString(dto));
            CommentResultInfoDto resultInfoDto = new CommentResultInfoDto();
            // 步骤1：检查参数
            checkParam(dto);
            // 步骤2：构建查询条件
            CommentParam queryParam = buildQueryCommentParam(dto);
            // 模块:资源id:页码
            // 如果命中缓存，那就返回
            String key = RedisUtils.getCommentKey(dto);
            RBucket<CommentResultInfoDto> bucket = redissonClient.getBucket(key);
            CommentResultInfoDto commentResultInfoDto = bucket.get();
            if(commentResultInfoDto!=null){
                log.info("命中缓存");
                 return commentResultInfoDto;
            }
            // 步骤3：查询评论总数
            log.info("查询评论-service层-数据库-入参:{}", JSON.toJSONString(queryParam));
            int total = commentMapper.countCommentByParam(queryParam);
            resultInfoDto.setTotal(Long.valueOf(total+""));
            if(total<=0){
                return resultInfoDto;
            }
            // 步骤4：查询评论列表
//            TbCommentExample tbCommentExample = new TbCommentExample();
//            TbCommentExample.Criteria criteria = tbCommentExample.createCriteria();
//            criteria.andResourceIdEqualTo(queryParam.getResourceId());
//            criteria.andModuleEqualTo(queryParam.getModule());
//            criteria.andIsDeleteEqualTo(queryParam.getIsDelete());
//            criteria.andParentCommentIdIsNull();
//            List<TbComment> tbComments = commentDao.selectByExampleWithBLOBs(tbCommentExample);
            List<CommentEntity> rootCommentList = commentMapper.queryCommentByParam(queryParam);
            log.info("查询评论-service层-数据库-出参:{}", JSON.toJSONString(rootCommentList));
            // 评论ID列表
            List<Long> commentIds = rootCommentList.stream().map(CommentEntity::getId).collect(Collectors.toList());

            // 已点赞集合
            Set<Long> trueLikeSet = new HashSet<>();
            // 如果没登录，那就是全没点赞
            if(TokenUtils.getUserId()!=null){
                HasLikesParam hasLikesParam = getHasLikesParam(dto.getModule(), commentIds);
                List<HasLikeDto> hasLikeDtos = mediaRpcService.queryHasLikeByParam(hasLikesParam);
                buildTrueLikeSet(hasLikeDtos, trueLikeSet);
            }

            // 步骤5：组装结果集
            List<CommentDetailInfoDto> list = buildResultList(rootCommentList,dto.getReplyNum(),trueLikeSet);

            resultInfoDto.setList(list);
            log.info("查询评论-service层-queryCommentByParam-出参:{}", resultInfoDto);
            // 存在一个问题：不管list是否有真实数据，都会缓存。
            if(dto.getPageNum()==1 && !CollectionUtils.isEmpty(resultInfoDto.getList())){
                bucket.set(resultInfoDto,30, TimeUnit.MINUTES);
                log.info("已缓存第一页数据");
            }
            return resultInfoDto;
        }catch (Exception e){
            log.error("查询评论-service层-queryCommentByParam-异常:", e);
            return new CommentResultInfoDto();
        }

    }

    private static void buildTrueLikeSet(List<HasLikeDto> hasLikeDtos, Set<Long> trueLikeSet) {
        if(CollectionUtils.isEmpty(hasLikeDtos)){
            return;
        }
        for (int i = 0; i < hasLikeDtos.size(); i++) {
            HasLikeDto hasLikeDto = hasLikeDtos.get(i);
            if (hasLikeDto.getHasLike() != null && hasLikeDto.getHasLike()) {
                trueLikeSet.add(hasLikeDto.getTargetId());
            }
        }
    }

    private static HasLikesParam getHasLikesParam(Integer module, List<Long> commentIds) {
        HasLikesParam hasLikesParam = new HasLikesParam();
        hasLikesParam.setUserId(TokenUtils.getUserId());
        hasLikesParam.setTargetIds(commentIds);
        hasLikesParam.setModule(module);
        hasLikesParam.setType(TbLikeTypeEnum.COMMENT.getCode());
        return hasLikesParam;
    }

    @Override
    public CommentResultInfoDto queryCommentList(CommentInfoDto dto) {
        try {
            log.info("查询评论-service层-queryCommentList-入参:{}", JSON.toJSONString(dto));
            CommentResultInfoDto resultInfoDto = new CommentResultInfoDto();
            // 步骤1：检查参数
            checkCommentListParam(dto);
            // 步骤2：构建查询条件
            TbCommentExample example = new TbCommentExample();
            TbCommentExample.Criteria criteria = example.createCriteria();
            if(dto.getUserId()!=null){
                criteria.andUserIdEqualTo(dto.getUserId());
            }
            criteria.andModuleEqualTo(dto.getModule());
            criteria.andIsDeleteEqualTo(0);
            example.setLimit(dto.getPageSize());
            example.setOffset((long)buildOffset(dto.getPageNum(),dto.getPageSize()));
            // 步骤3：查询评论总数
            long count = commentDao.countByExample(example);
            resultInfoDto.setTotal(count);
            if(count<=0L){
                return resultInfoDto;
            }
            List<TbComment> tbComments = commentDao.selectByExampleWithBLOBs(example);
            resultInfoDto.setList(buildCommentDetailList(tbComments));

            log.info("查询评论-service层-queryCommentList-出参:{}", resultInfoDto);
            return resultInfoDto;
        }catch (Exception e){
            log.error("查询评论-service层-queryCommentList-异常:", e);
            return new CommentResultInfoDto();
        }
    }

    private List<CommentDetailInfoDto> buildCommentDetailList(List<TbComment> tbComments) {
        if(CollectionUtils.isEmpty(tbComments)){
            return new ArrayList<>();
        }
        List<CommentDetailInfoDto> commentDetailInfoDtos = new ArrayList<>();
        for (int i = 0; i < tbComments.size(); i++) {
            TbComment tbComment = tbComments.get(i);
            CommentDetailInfoDto commentDetailInfoDto = buildCommentDetailInfoDto(tbComment);
            commentDetailInfoDtos.add(commentDetailInfoDto);
        }
        return commentDetailInfoDtos;
    }

    /**
     * 根据评论ID查询评论详情
     * @param id
     * @return
     */
    @Override
    public CommentDetailInfoDto queryCommentDetailById(Long id) {
        try {
            log.info("查询评论详情-service层-queryCommentDetailById-入参:{}", id);
            TbComment comment = commentDao.selectByPrimaryKey(id);
            CommentDetailInfoDto commentDetailInfoDto = buildCommentDetailInfoDto(comment);
            log.info("查询评论详情-service层-queryCommentDetailById-出参:{}", commentDetailInfoDto);
            return commentDetailInfoDto;
        }catch (Exception e){
            log.error("查询评论详情-service层-queryCommentDetailById-异常:", e);
            return new CommentDetailInfoDto();
        }
    }

    @Override
    public List<SimpleCommentInfoDto> batchQueryCommentByResourceIds(BatchQueryCommentDto dto) {
        try {
            log.info("批量查询查询评论详情-batchQueryCommentByResourceIds-入参:{}", dto);
            List<Long> resourceIds = dto.getResourceIds();
            List<CompletableFuture<Void>> futures = new ArrayList<>();
            Integer module = dto.getModule();
            List<SimpleCommentInfoDto> simpleCommentInfoDtos = new ArrayList<>();
            for (int i = 0; i < resourceIds.size(); i++) {
                Long resourceId = resourceIds.get(i);
                CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
                    try {
                        SimpleCommentInfoDto simpleCommentInfoDto = processQueryCommentSubTask(module, resourceId);
                        if(simpleCommentInfoDto!=null){
                            simpleCommentInfoDtos.add(simpleCommentInfoDto);
                        }
                    } catch (Exception e) {
                        log.error("子任务处理失败", e);
                    }
                },threadPoolTaskExecutor);
                futures.add(future);
            }
            // 等待所有子任务完成
            CompletableFuture<Void> allFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
            allFuture.join();
            log.info("批量查询查询评论详情-batchQueryCommentByResourceIds-出参:{}", simpleCommentInfoDtos);
            return simpleCommentInfoDtos;
        }catch (Exception e){
            log.error("批量查询查询评论详情-batchQueryCommentByResourceIds-异常:", e);
            return new ArrayList<>();
        }
    }

    private SimpleCommentInfoDto processQueryCommentSubTask(Integer module, Long resourceId) {
        if(module==null || resourceId==null){
            return null;
        }
        TbCommentExample tbCommentExample = new TbCommentExample();
        TbCommentExample.Criteria criteria = tbCommentExample.createCriteria();
        criteria.andModuleEqualTo(module);
        criteria.andResourceIdEqualTo(resourceId);
        criteria.andIsDeleteEqualTo(0);
        tbCommentExample.setLimit(1);
        tbCommentExample.setOrderByClause("create_time desc");
        List<TbComment> tbComments = commentDao.selectByExample(tbCommentExample);
        if(CollectionUtils.isEmpty(tbComments)){
            return null;
        }
        return buildSimpleCommentInfoDto(tbComments.get(0));
    }

    private SimpleCommentInfoDto buildSimpleCommentInfoDto(TbComment tbComment) {
        if(tbComment==null){
            return null;
        }
        SimpleCommentInfoDto simpleCommentInfoDto = new SimpleCommentInfoDto();
        simpleCommentInfoDto.setId(tbComment.getId());
        UserInfoDto userInfo = userRpcService.getUserInfo(tbComment.getUserId());
        simpleCommentInfoDto.setName(userInfo==null?null:userInfo.getName());
        simpleCommentInfoDto.setResourceId(tbComment.getResourceId());
        simpleCommentInfoDto.setContent(tbComment.getContent());
        return simpleCommentInfoDto;
    }

    /**
     * 构建结果集
     * @param comment
     * @return {@link CommentDetailInfoDto }
     */
    private CommentDetailInfoDto buildCommentDetailInfoDto(TbComment comment) {
        if(comment==null){
            return null;
        }
        CommentDetailInfoDto commentDetailInfoDto = new CommentDetailInfoDto();
        commentDetailInfoDto.setId(comment.getId());
        commentDetailInfoDto.setUserId(comment.getUserId());
        commentDetailInfoDto.setParentCommentId(comment.getParentCommentId());
        commentDetailInfoDto.setRootCommentId(comment.getRootCommentId());
        commentDetailInfoDto.setUsername(CommentExtendUtils.getUsernameOnExtend(comment.getExtend()));
        commentDetailInfoDto.setAvatar(CommentExtendUtils.getAvatarOnExtend(comment.getExtend()));
        commentDetailInfoDto.setRepliedUsername(CommentExtendUtils.getRepliedUsernameOnExtend(comment.getExtend()));
        commentDetailInfoDto.setModule(comment.getModule());
        commentDetailInfoDto.setResourceId(comment.getResourceId());
        commentDetailInfoDto.setContent(comment.getContent());
        commentDetailInfoDto.setStatus(comment.getStatus());
        commentDetailInfoDto.setScore(comment.getScore());
        commentDetailInfoDto.setStarNum(comment.getStarNum());
        commentDetailInfoDto.setIsDelete(comment.getIsDelete());
        commentDetailInfoDto.setCreateTime(comment.getCreateTime());
        commentDetailInfoDto.setUpdateTime(comment.getUpdateTime());
        commentDetailInfoDto.setReplyList(new ArrayList<>());
        return commentDetailInfoDto;
    }

    private static TbCommentExample buildReplyParam(Long id, Integer replyNum) {
        TbCommentExample tbCommentExample = new TbCommentExample();
        TbCommentExample.Criteria criteria = tbCommentExample.createCriteria();
        criteria.andRootCommentIdEqualTo(id);
        criteria.andIsDeleteEqualTo(0);
        criteria.andParentCommentIdIsNotNull();
        tbCommentExample.setLimit(replyNum);
        tbCommentExample.setOrderByClause("create_time desc");
        return tbCommentExample;
    }

    /**
     * 构建结果集
     *
     * @param commentEntities
     * @param replyNum
     * @param trueLikeSet
     * @return
     */
    private List<CommentDetailInfoDto> buildResultList(List<CommentEntity> commentEntities, Integer replyNum, Set<Long> trueLikeSet) {
        if(CollectionUtils.isEmpty(commentEntities)){
            return new ArrayList<>();
        }
        List<CommentDetailInfoDto> resultInfoDtos = new ArrayList<>();

        for (int i = 0; i < commentEntities.size(); i++) {
            CommentEntity commentEntity = commentEntities.get(i);
            if(commentEntity==null){
                continue;
            }
            CommentDetailInfoDto target = new CommentDetailInfoDto();
            BeanUtils.copyProperties(commentEntity,target);
            target.setHasStar(trueLikeSet.contains(target.getId()));
            explainExtendToTarget(target,commentEntity.getExtend());
            target.setReplyList(buildReplyInfoResultList(commentEntity,replyNum));
            target.setReplyCount(buildReplyCount(commentEntity));
            resultInfoDtos.add(target);
        }
        return resultInfoDtos;
    }

    private Integer buildReplyCount(CommentEntity commentEntity) {
        if(commentEntity==null || commentEntity.getId()==null){
            return 0;
        }
        TbCommentExample tbCommentExample = new TbCommentExample();
        TbCommentExample.Criteria criteria = tbCommentExample.createCriteria();
        criteria.andRootCommentIdEqualTo(commentEntity.getId());
        criteria.andIsDeleteEqualTo(0);
        criteria.andParentCommentIdIsNotNull();
        return (int)commentDao.countByExample(tbCommentExample);
    }

    private void explainExtendToTarget(CommentDetailInfoDto target, String extend) {
        if(StringUtils.isBlank(extend)){
            return;
        }
        target.setUsername(CommentExtendUtils.getUsernameOnExtend(extend));
        target.setRepliedUsername(CommentExtendUtils.getRepliedUsernameOnExtend(extend));
        target.setAvatar(CommentExtendUtils.getAvatarOnExtend(extend));
    }

    private List<ReplyInfoDto> buildReplyInfoResultList(CommentEntity commentEntity, Integer replyNum) {
        if(commentEntity==null){
            return new ArrayList<>();
        }
        TbCommentExample replyParam = buildReplyParam(commentEntity.getId(),replyNum);
        List<TbComment> replyList = commentDao.selectByExampleWithBLOBs(replyParam);
        if(CollectionUtils.isEmpty(replyList)){
            return new ArrayList<>();
        }
        List<Long> replyIdList = replyList.stream().map(TbComment::getId).collect(Collectors.toList());
        // 获取点赞集合
        Set<Long> trueLikeReplySet = new HashSet<>();
        if(TokenUtils.getUserId()!=null){
            HasLikesParam hasLikesParam = getHasLikesParam(commentEntity.getModule(), replyIdList);
            List<HasLikeDto> hasLikeDtos = mediaRpcService.queryHasLikeByParam(hasLikesParam);
            buildTrueLikeSet(hasLikeDtos, trueLikeReplySet);
        }

        List<ReplyInfoDto> targetList = new ArrayList<>();
        for (int i = 0; i < replyList.size(); i++) {
            TbComment replyInfo = replyList.get(i);
            ReplyInfoDto target =  new ReplyInfoDto();
            target.setUserId(replyInfo.getUserId()+"");
            target.setId(replyInfo.getId()+"");
            target.setRootId(replyInfo.getRootCommentId()+"");
            target.setResourceId(replyInfo.getResourceId()+"");
            target.setModule(replyInfo.getModule());
            target.setUsername(CommentExtendUtils.getUsernameOnExtend(replyInfo.getExtend()));
            target.setContent(replyInfo.getContent());
            target.setStarNum(replyInfo.getStarNum());
            target.setHasStar(trueLikeReplySet.contains(replyInfo.getId()));
            target.setReplyTime(DateUtils.date2Str(replyInfo.getCreateTime(),DateUtils.YYYY_MM_DD_HH_MM_SS));
            target.setAvatar(CommentExtendUtils.getAvatarOnExtend(replyInfo.getExtend()));
            target.setRepliedName(CommentExtendUtils.getRepliedUsernameOnExtend(replyInfo.getExtend()));
            target.setRepliedUserId(CommentExtendUtils.getRepliedUserIdOnExtend(replyInfo.getExtend()));
            target.setParentId(replyInfo.getParentCommentId()!=null?replyInfo.getParentCommentId()+"":null);
            target.setStatus(replyInfo.getStatus());
            targetList.add(target);
        }
        return targetList;
    }





    /**
     * 构建查询评论的条件
     * @param dto
     * @return
     */
    private CommentParam buildQueryCommentParam(CommentInfoDto dto) {
        CommentParam commentParam = new CommentParam();
        commentParam.setModule(dto.getModule());
        commentParam.setResourceId(dto.getResourceId());
        commentParam.setLimit(dto.getPageSize());
        commentParam.setIsDelete(dto.getIsDelete());
        commentParam.setOffset(buildOffset(dto.getPageNum(),dto.getPageSize()));
        if(dto.getOrder()==null){
            commentParam.setOrderBy("create_time");
            commentParam.setOrderDirection("desc");
        }else{
            if(dto.getOrder()==2){
                commentParam.setOrderBy("star_num");
                commentParam.setOrderDirection("desc");
            }else{
                commentParam.setOrderBy("create_time");
                commentParam.setOrderDirection("asc");
            }
        }
        return commentParam;
    }

    /**
     * 计算偏移量
     * @param pageNum
     * @param pageSize
     * @return
     */
    private Integer buildOffset(Integer pageNum, Integer pageSize) {
        Integer offset = (pageNum-1)* pageSize;
        return Math.max(0,offset);
    }

    private void checkParam(CommentInfoDto dto) {
        Assert.isTrue(dto!=null,"参数不能为空");
        Assert.isTrue(dto.getModule()!=null,"模块不能为空");
        Assert.isTrue(dto.getResourceId()!=null,"资源id不能为空");
        // 补全分页信息
        if(dto.getPageNum()==null || dto.getPageSize()==null || dto.getReplyNum()==null){
            dto.setPageNum(1);
            dto.setPageSize(10);
            dto.setReplyNum(3);
        }
    }
    private void checkCommentListParam(CommentInfoDto dto) {
        Assert.isTrue(dto!=null,"参数不能为空");
        Assert.isTrue(dto.getModule()!=null,"模块不能为空");
        // 补全分页信息
        if(dto.getPageNum()==null || dto.getPageSize()==null){
            dto.setPageNum(1);
            dto.setPageSize(10);
        }
    }
}
